package com.github.monkeywie.proxyee;

import com.github.monkeywie.proxyee.intercept.HttpProxyInterceptInitializer;
import com.github.monkeywie.proxyee.intercept.HttpProxyInterceptPipeline;
import com.github.monkeywie.proxyee.intercept.HttpTunnelIntercept;
import com.github.monkeywie.proxyee.intercept.common.CertDownIntercept;
import com.github.monkeywie.proxyee.intercept.common.FullResponseIntercept;
import com.github.monkeywie.proxyee.intercept.common.HeaderIntercept;
import com.github.monkeywie.proxyee.intercept.common.LogIntercept;
import com.github.monkeywie.proxyee.log.LogRecorder;
import com.github.monkeywie.proxyee.log.LogRecorderFactory;
import com.github.monkeywie.proxyee.server.HttpProxyServer;
import com.github.monkeywie.proxyee.server.HttpProxyServerConfig;
import com.github.monkeywie.proxyee.util.ProtoUtil;

/**
 * @Author LiWei
 * @Description
 * @Date 2019/9/23 17:30
 */
public class HttpProxyServerApp {
    private final static LogRecorder logRecorder= LogRecorderFactory.getRecorder(HttpProxyServerApp.class);
    public static void main(String[] args) {
        int port = 11221;
        if (args.length > 0) {
            port = Integer.valueOf(args[0]);
        }
        HttpProxyServerConfig config =  new HttpProxyServerConfig();
        config.setHandleSsl(false);
        config.setUser("haha");
        config.setPwd("123456");
        HttpProxyInterceptInitializer interceptInitializer = new HttpProxyInterceptInitializer() {
            public void init(HttpProxyInterceptPipeline pipeline) {
                pipeline.addLast(new CertDownIntercept());
                pipeline.addLast(new LogIntercept());
                pipeline.addLast(new HeaderIntercept());
            }
        };

        logRecorder.info("start proxy server ,port="+port);
        new HttpProxyServer().serverConfig(config)
                .proxyInterceptInitializer(interceptInitializer)
                .tunnelIntercept(new LogIntercept())
                .start(port);
    }
}
